//弹窗信息内容
import React from 'react';
import { connect } from 'dva';
import { FormGroup, DATA_ENTRY, codeType } from '../../../../comps';
class FundLayer extends React.Component {
  constructor() {
    super();
    this.state = {
      fundType: '0',
    };
  }
  componentDidMount() {
    this.props.onRef && this.props.onRef(this);
  }
  UNSAFE_componentWillReceiveProps(nextPorps) {
    if (nextPorps.LayerContent != this.props.LayerContent && nextPorps.LayerContent) {
      this.setState({
        fundType: nextPorps?.LayerContent?.fundType,
      });
    }
  }
  //选择基金类型
  changeData = (data) => {
    const { type } = this.props;
    this.setState(
      {
        fundType: data,
      },
      () => {
        if (type == 'add') {
          this.formContent.props.form.setFieldsValue({
            tradingCode: null,
          });
        }
      },
    );
  };
  getFormData = (callback) => {
    this.formContent.props.form.validateFields((error, values) => {
      if (error) {
        return;
      }
      callback({
        ...values,
      });
    });
  };
  reset = () => {
    this.formContent.props.form.resetFields();
    this.setState({
      fundType: '0',
    });
  };
  render() {
    const {
      LayerContent,
      type,
      fundSupervisionMsgMaintainM: { dictMap },
    } = this.props;
    const { fundType } = this.state;
    const formItemLayoutDefine = {
      labelCol: {
        xs: { span: 6, offset: 0 },
        sm: { span: 6, offset: 0 },
        md: { span: 6, offset: 0 },
        lg: { span: 6, offset: 0 },
        xl: { span: 6, offset: 0 },
        xxl: { span: 6, offset: 0 },
      },
      wrapperCol: {
        xs: { span: 18, offset: 0 },
        sm: { span: 18, offset: 0 },
        md: { span: 18, offset: 0 },
        lg: { span: 18, offset: 0 },
        xl: { span: 18, offset: 0 },
        xxl: { span: 18, offset: 0 },
      },
    };
    return (
      <div>
        <FormGroup
          widthSet={460}
          dataSource={[
            {
              dataIndex: 'fundType',
              title: '基金类型',
              type: DATA_ENTRY.SELECT,
              disabled: type == 'edit' ? false : false,
              rules: [
                {
                  required: true,
                  message: '请选择基金类型',
                },
              ],
              span: 24,
              isInput: true,
              initialValue: type == 'add' ? '0' : LayerContent?.fundType,
              positionBody: true,
              dataSource: (dictMap['fund_fundType'] || []).map((item) => {
                return { title: item.value, value: item.code };
              }),
              formItemLayoutDefine,
              onChange: this.changeData,
            },
            {
              hide: fundType != '0',
              dataIndex: 'tradingCode',
              title: '证券代码',
              type: DATA_ENTRY.SECURITIESCODE,
              codeType: codeType.gmjj,
              queryItems: { _: 123456789 },
              initialValue: LayerContent?.tradingCode ? LayerContent.exchangecode + '-' + LayerContent.tradingCode : undefined,
              rules: [{ required: true, message: '请选择证券代码' }],
              onRef: (ref) => (this.fundIdSetGM = ref),
              formItemLayoutDefine,
              positionBody: true,
              disabled: type == 'edit' ? true : false,
            },
            {
              hide: fundType == '0',
              dataIndex: 'tradingCode',
              title: '证券代码',
              type: DATA_ENTRY.SECURITIESCODE,
              codeType: codeType.smjj,
              initialValue: LayerContent?.tradingCode ? LayerContent.exchangecode + '-' + LayerContent.tradingCode : undefined,
              rules: [{ required: true, message: '请选择证券代码' }],
              formItemLayoutDefine,
              onRef: (ref) => (this.fundIdSetSM = ref),
              disabled: type == 'edit' ? true : false,
              positionBody: true,
            },
          ]}
          autoLayout={false}
          onRef={(ref) => (this.formContent = ref)}
        ></FormGroup>
      </div>
    );
  }
}
export default connect(({ fundSupervisionMsgMaintainM }) => ({ fundSupervisionMsgMaintainM }))(FundLayer);
